package com.atguigu.rabbit.producer;

import com.atguigu.rabbit.producer.entity.myCorrelationData;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @BelongsProject: rabbitmq-parent-0528
 * @BelongsPackage: com.atguigu.rabbit.producer
 * @Author: jiangyi
 * @CreateTime: 2025-09-15  22:47
 * @Description: TODO
 * @Version: 1.0
 */

@SpringBootTest
public class delayedQueue01 {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void delayedQueueDemo() {

        myCorrelationData correlationData = new myCorrelationData();
        correlationData.setId("1999999999999999");
        correlationData.setMessage("延迟队列");
        Object str = "hello delay...";
        rabbitTemplate.convertAndSend("exchange.delay.order", "routing.delay.order", str, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                // 设置延迟时间
                message.getMessageProperties().setDelay(10000);

                return message;
            }
        }, correlationData);
    }

}
